﻿#include "pch.h"
#include "ShaderLibrary.h"

#include "core/log/LogSystem.h"

namespace Engine
{
	void ShaderLibrary::Add(const std::string& name, const Ref<AbstractShader>& shader)
	{
		ENGINE_ASSERT(!Exists(name), "Shader already exists!")
		shaders[name] = shader;
	}

	void ShaderLibrary::Add(const Ref<AbstractShader>& shader)
	{
		auto& name = shader->GetName();
		Add(name, shader);
	}

	Ref<AbstractShader> ShaderLibrary::Load(const std::string& filepath)
	{
		auto shader = AbstractShader::Create(filepath);
		Add(shader);
		return shader;
	}

	Ref<AbstractShader> ShaderLibrary::Load(const std::string& name, const std::string& filepath)
	{
		auto shader = AbstractShader::Create(filepath);
		Add(name, shader);
		return shader;
	}

	Ref<AbstractShader> ShaderLibrary::Get(const std::string& name)
	{
		ENGINE_ASSERT(Exists(name), "Shader not found!")
		return shaders[name];
	}

	bool ShaderLibrary::Exists(const std::string& name) const
	{
		return shaders.find(name) != shaders.end();
	}
}
